$(function () {
    var $windos;
    var $waterT = $('.water_temperature_box');
    var $temperature = $('.temperature_date_box .temperature');
    var $rPointer = $('.r_pointer');
    var $vPointer = $('.v_pointer');
    var $oilBox = $('.oil_box');
    var $oilContent = $('.oil_content');
    var $rotateV;
    var dateBox = $('.date_box');
    var $nowTime = new Date();
    dateBox.text($nowTime.toLocaleDateString());

    function waterTemperature(temperature) {
        if (temperature < 101){
            $waterT.height(temperature * ($waterT.height() / 100));
            $temperature.text(temperature + '℃')
        }else {
            console.log('data error')
        }
    }

    function rSpeed(speed) {
        speed < 10 ? $rPointer.css('transform' , "rotate(" + (speed * 36 - 54) + 'deg' +")") : console.log('data error');
    }

    function vSpeed(speed) {
        if(speed < 260) {
            $windos = $(window).width();
            $windos > 768 ? $rotateV = 145 : $rotateV = 38;
            $vPointer.css('transform' , "rotate(" + (speed * 1.2 + $rotateV) + 'deg' +")");
            $('.v_speed span').eq(0).text(speed)
        }else {
            console.log('data error')
        }
    }

    function oilContentData(oil) {
        $oilContentH = $oilContent.height();
        $oilContent.height(oil * $oilContentH);
        if (oil < 1.01 && oil > 0.25){
            $oilBox.addClass('green_oil_box').removeClass('red_oil_box');
        }else if (oil < 0.251){
            $oilBox.addClass('red_oil_box').removeClass('green_oil_box');
        }else {
            console.log('data error')
        }
    }

    waterTemperature(50);
    rSpeed(0);
    vSpeed(0);
    oilContentData(0.75);

});